/**
 * @param {string[]} startWords
 * @param {string[]} targetWords
 * @return {number}
 */
 var wordCount = function(startWords, targetWords) {
  const n = startWords.length, m = targetWords.length
  const map = {}
  const hash = (s) => s.charCodeAt(0) - 'a'.charCodeAt(0)
  for(let i = 0; i<n; i++){
    let now = new Array(26).fill(0)
    for(let ch of startWords[i]){
      now[hash(ch)]++
    }
    let len = startWords[i].length
    map[len] = map[len] || []
    map[len].push(now)
  }
  let ans = 0
  for(let i = 0; i<m; i++){
    const now = new Array(26).fill(0)
    for(let ch of targetWords[i]){
      now[hash(ch)]++
    }
    let len = targetWords[i].length
    if(map[len-1]){
      for(let cnt of map[len-1]){
        if(check(cnt, now)){
          ans++
          break
        }
      }
    }
    
  }
  return ans
};

function check(arr1, arr2){
  let dif = 0
  for(let i = 0; i<26; i++){
    if(arr1[i] > arr2[i]) return false
    dif += arr2[i] - arr1[i]
  }
  return dif === 1
}